/**
 * Copyright (C)  2011  chen wei hua.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 2.0
 * or any later version published by the Free Software Foundation;
 * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 * A copy of the license is included in the section entitled "GNU Free Documentation License".
 */
package com.javaeye.chenweihuacwh.service.baseData;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.javaeye.chenweihuacwh.dao.baseData.LogisticsDAO;
import com.javaeye.chenweihuacwh.dto.baseData.Logistics;
import com.javaeye.chenweihuacwh.web.PageInfo;

public class LogisticsService implements ILogisticsService {
	
	private static Log log = LogFactory.getLog(ProductService.class);
	
	private LogisticsDAO dao;
	
	public void setDao(LogisticsDAO dao) {
		this.dao = dao;
	}

	@Override
	public Logistics getLogistics(String id) {
		int intId = Integer.parseInt(id);
		Logistics logistics = dao.getLogistics(intId);
		if (logistics == null) {
			log.warn("在数据库中未找到指定的物流公司  id：" + id);
		}
		return logistics;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Logistics> getLogisticsList(Logistics condition, PageInfo pageInfo) {
		List results = dao.getPageData(condition, pageInfo);
		if (results == null || results.size() == 0) {
			log.warn("在数据库中未找到物流公司数据");
		}
		return results;
	}

	@Override
	public void removeLogistics(String id) {
		int intId = Integer.parseInt(id);
		dao.removeLogistics(intId);
	}

	@Override
	public Logistics saveLogistics(Logistics logistics) {
		dao.saveLogistics(logistics);
		return logistics;
	}
	
	public List<Logistics> getAutoCompleteLogistics(String name, int size) {
		List<Logistics> result = dao.getAutoCompleteLogistics(name, size);
		if (result == null || result.size() == 0) {
			log.warn("在数据库中未找到物流公司数据");
		}
		return result;
	}
}
